package com.ssy.lingxi.order.entity;

import com.fasterxml.jackson.annotation.JsonManagedReference;

import javax.persistence.*;
import java.io.Serializable;
import java.time.LocalDateTime;
import java.util.Set;

/**
 * 平台后台 - 交易流程配置
 *
 * @author 万宁
 * @version 2.0.0
 * @date 2021-07-23
 */
@Entity
@Table(schema = "public", name = "ord_platform_trade_process", indexes = {@Index(name = "ord_platform_trade_process_type_idx", columnList = "processType"), @Index(name = "ord_platform_trade_process_status_idx", columnList = "status"), @Index(name = "ord_platform_trade_process_create_time_idx", columnList = "createTime")})
public class PlatformTradeProcessDO implements Serializable {
    private static final long serialVersionUID = -6779610996635775460L;

    /**
     * 主键Id
     */
    @Id
    @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "ord_platform_trade_process_seq")
    @SequenceGenerator(sequenceName = "ord_platform_trade_process_seq", name = "ord_platform_trade_process_seq", allocationSize = 1)
    private Long id;

    /**
     * 新增、修改时间
     */
    @Column(columnDefinition = "timestamp")
    private LocalDateTime createTime;

    /**
     * 流程名称
     */
    @Column(columnDefinition = "varchar(50)")
    private String name;

    /**
     * 流程对应的工作流的Key
     */
    @Column(columnDefinition = "varchar(100)")
    private String processKey;

    /**
     * 流程类型，定义在 OrderTradeProcessTypeEnum 中
     */
    @Column
    private Integer processType;

    /**
     * 流程中需要支付环节的次数
     */
    @Column
    private Integer payTimes;

    /**
     * 流程类型，定义在 WorkflowProcessKindEnum 中， 1-内部流程，2-外部流程，3-复杂流程
     */
    @Column
    private Integer processKind;

    /**
     * 启动后是否需要执行第一个步骤，即调用工作流提供的startProcessAndExecFirstStep接口
     */
    @Column
    private Boolean skipFirstStep;

    /**
     * 状态，0-停用，1-启用
     */
    @Column
    private Integer status;

    /**
     * 是否适用于所有会员
     */
    @Column
    private Boolean allMembers;

    /**
     * 一对一单向关联基础交易流程
     */
    @OneToOne(cascade = CascadeType.DETACH, fetch = FetchType.LAZY)
    @JoinColumn(name="platform_trade_process_id",referencedColumnName="id")
    private BaseTradeProcessDO process;

    /**
     * 一对多双向关联适用会员
     */
    @JsonManagedReference
    @OneToMany(mappedBy = "process", cascade = {CascadeType.DETACH, CascadeType.REMOVE}, fetch = FetchType.LAZY)
    private Set<PlatformTradeProcessMemberDO> members;

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public LocalDateTime getCreateTime() {
        return createTime;
    }

    public void setCreateTime(LocalDateTime createTime) {
        this.createTime = createTime;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getProcessKey() {
        return processKey;
    }

    public void setProcessKey(String processKey) {
        this.processKey = processKey;
    }

    public Integer getProcessType() {
        return processType;
    }

    public void setProcessType(Integer processType) {
        this.processType = processType;
    }

    public Integer getPayTimes() {
        return payTimes;
    }

    public void setPayTimes(Integer payTimes) {
        this.payTimes = payTimes;
    }

    public Integer getProcessKind() {
        return processKind;
    }

    public void setProcessKind(Integer processKind) {
        this.processKind = processKind;
    }

    public Boolean getSkipFirstStep() {
        return skipFirstStep;
    }

    public void setSkipFirstStep(Boolean skipFirstStep) {
        this.skipFirstStep = skipFirstStep;
    }

    public Integer getStatus() {
        return status;
    }

    public void setStatus(Integer status) {
        this.status = status;
    }

    public Boolean getAllMembers() {
        return allMembers;
    }

    public void setAllMembers(Boolean allMembers) {
        this.allMembers = allMembers;
    }

    public BaseTradeProcessDO getProcess() {
        return process;
    }

    public void setProcess(BaseTradeProcessDO process) {
        this.process = process;
    }

    public Set<PlatformTradeProcessMemberDO> getMembers() {
        return members;
    }

    public void setMembers(Set<PlatformTradeProcessMemberDO> members) {
        this.members = members;
    }
}
